---
title: Web Component
---

<Callout>
  如果你正在寻找使用 Web Component 组件作为自定义组件的方法，请参阅[此处](/guides/sheets/ui/components#web-component)。
</Callout>

Univer 支持在 Web Component 中集成。

<PlaygroundFrame lang="zh-CN" slug="docs/lit" clickToShow />

### 示例代码

以下代码是通过 Lit 框架将 Univer 集成到 Web Component 中的示例。

```typescript
import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'
import docsCoreZhCN from '@univerjs/preset-docs-core/locales/zh-CN'
import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'
import { html, LitElement } from 'lit'

class MyWebComponent extends LitElement {
  override firstUpdated() {
    const container = this.renderRoot.querySelector('#containerId') as HTMLDivElement

    const { univerAPI } = createUniver({
      locale: LocaleType.ZH_CN,
      locales: {
        [LocaleType.ZH_CN]: mergeLocales(
          docsCoreZhCN,
        ),
      },
      presets: [
        UniverDocsCorePreset({
          container,
        }),
      ],
    })

    univerAPI.createUniverDoc({})
  }

  override render() {
    return html`
      <link rel="stylesheet" href="https://unpkg.com/@univerjs/preset-docs-core/lib/index.css">
      <div style="height: 100%;" id="containerId" />
    `
  }
}

window.customElements.define('my-univer', MyWebComponent)
```
